from django.db import models
from django import forms

# Create your models here.
from django.forms import ModelForm, widgets as wid


class BlogPost(models.Model):
    title = models.CharField(max_length=100)
    body = models.TextField()
    timestamp = models.DateTimeField()

    class Meta:
        # db_table=''
        ordering = ('-timestamp',)


class BlogPostForm(ModelForm):
    class Meta:
        model = BlogPost
        fields = '__all__'  # 字段
        exclude = ('timestamp',)  # 排除的字段
        help_texts = '帮助信息'  # 帮助信息
        error_messages = {
            'title': {'required': '新闻标题必须填写', },
            'body': {'required': '请填写新闻内容', },
        }
        widgets = {
            'body': wid.Textarea(attrs={'row': 3})
        }
        labels = {
            'title': '新闻标题',
            'body': '新闻内容',
        }


class CodeEntity(forms.Form):
    """
    接收前台提交的实体
    """
    table_name =forms.CharField(max_length=50)

